package com.foreknow.demo0927;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class LogOn {
    static String arrId[] = {};
    static String arrPw[] = {};

    public static void ZuCe(String Id, String Pw) {
        arrId = Arrays.copyOf(arrId, arrId.length + 1);
        arrPw = Arrays.copyOf(arrPw, arrPw.length + 1);
        arrId[arrId.length - 1] = Id;
        arrPw[arrPw.length - 1] = Pw;
    }

    public static void XinXi() {
        Random r = new Random();
        int num = r.nextInt(10000) + 1000;
        System.out.println("注册成功，请记好您的会员卡号");
        System.out.println("用户名   密码   卡号");
        System.out.println(arrId[arrId.length - 1] + "   " + arrPw[arrPw.length - 1] + "   " + num);
    }

    public static void DengLu() {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入用户名:");
        String Id = sc.next();
        int index = -1;
        for (int i = 0; i < arrId.length; i++) {
            if (Id.equals(arrId[i])) {
                index = i;
            }
            break;
        }
        for (int i = 1; i <= 3; i++) {
            System.out.print("请输入密码:");
            String Pw = sc.next();
            if (Pw.equals(arrPw[index])) {
                System.out.println("登录成功!欢迎" + Id);
                break;
            } else {
                int j = 3 - i;
                if (j > 0) {
                    System.out.println("密码不正确,请重新输入,还有" + (3 - i) + "次机会");
                    continue;
                } else {
                    System.out.println("密码不正确，已没有输入次数!");
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean b = true;
        while (b) {
            System.out.println("*****欢迎进入奖客富翁系统*****");
            System.out.println("1.注册");
            System.out.println("2.登录");
            System.out.println("3.抽奖");
            System.out.println("**************************");
            System.out.println("请选择菜单:");
            int i = sc.nextInt();
            switch (i) {
                case 1:
                    System.out.println("[奖客富翁系统>注册]");
                    System.out.print("请输入用户名:");
                    String Id = sc.next();
                    System.out.print("请输入密码:");
                    String Pw = sc.next();
                    ZuCe(Id, Pw);
                    XinXi();
                    System.out.print("继续吗？（y/n）");
                    String s1 = sc.next();
                    switch (s1) {
                        case "y":
                            continue;
                        case "n":
                            b = false;
                            break;
                    }
                    break;
                case 2:
                    System.out.println("[奖客富翁系统>登录]");
                    DengLu();
                    System.out.print("继续吗？（y/n）");
                    String s3 = sc.next();
                    switch (s3) {
                        case "y":
                            continue;
                        case "n":
                            b = false;
                            break;
                    }
                    break;
                case 3:
                    System.out.println("[奖客富翁系统>抽奖]");
                    break;
            }
            break;
        }
    }
}

